home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_shs_wolf.cog < prev    next >
Text File  |  1999-11-15  |  11KB  |  459 lines

  1. # Jones 3D Cog Script
  2. #
  3. # shs_wolf.cog   
  4. #
  5. # [SCHOLL]
  6. #
  7. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  8. #
  9. # ========================================================================================
  10. symbols
  11.  
  12. message entered
  13. message    startup
  14. message    aievent
  15. message    arrivedwpnt
  16. message timer
  17. message user0
  18.  
  19. thing    t_Wolf
  20. thing    t_Indy        local
  21.  
  22. int        b_active=0        local
  23. int        n_eventType        local
  24. int        n_CrntAIMode     local
  25. int        n_OldAIMode     local
  26. int        n_Waypoint        local
  27. flex    f_DistToIndy    local 
  28. int        n_TimerID        local 
  29. flex    f_FleeTime        local
  30.  
  31. int        b_OKToStopFlee=0         local
  32. int        b_AttackOnStopFlee=0     local
  33. int        n_idx                    local
  34. int        b_WpntsActive=0            local
  35. int        n_FleeDir                local
  36.  
  37. vector    v_IndyPos        local
  38. vector    v_WolfPos        local
  39. vector    v_Temp            local
  40.  
  41.  
  42.  
  43. # ===========================FLEE WAYPOINTS================================================
  44. int            NUM_FLEE_WAYPOINTS=13            local
  45. thing        t_Waypoint00
  46. thing        t_Waypoint01
  47. thing        t_Waypoint02
  48. thing        t_Waypoint03
  49. thing        t_Waypoint04
  50. thing        t_Waypoint05
  51. thing        t_Waypoint06
  52. thing        t_Waypoint07
  53. thing        t_Waypoint08
  54. thing        t_Waypoint09
  55. thing        t_Waypoint10
  56. thing        t_Waypoint11
  57. thing        t_Waypoint12
  58.  
  59.  
  60. # ===========================SECTORS================================================
  61.  
  62. int            NUM_AUTO_FLEE_SECTORS=2     local
  63. sector        s_AutoFlee00            mask=0x5 # need entered messages from wolf
  64. sector        s_AutoFlee01            mask=0x5 # need entered messages from wolf
  65.  
  66. int            NUM_ACTIVATE_WPNT_SECTORS=3 local
  67. sector        s_ActivateWpnts00
  68. sector        s_ActivateWpnts01
  69. sector        s_ActivateWpnts02
  70.  
  71. int            NUM_DEACTIVATE_WPNT_SECTORS=3 local
  72. sector        s_DeactivateWpnts00
  73. sector        s_DeactivateWpnts01
  74. sector        s_DeactivateWpnts02
  75.  
  76. # ===========================MISC CONSTANTS================================================
  77.  
  78. flex    MIN_FLEE_DISTANCE=2.0            local # distance wolf wants to be from Indy before stopping fleeing
  79. flex    MIN_FLEE_RESTART_DISTANCE=1.0            local # distance wolf wants to be from Indy before stopping fleeing
  80. flex    MAX_FLEEATTACK_DISTANCE=1.0            local # 
  81. flex    MIN_FLEE_TIME=4.0                local 
  82. flex    VARIABLE_FLEE_TIME=3.0            local
  83.  
  84. int        TIMER_ID_OKAY_TO_STOP_FLEE=0    local
  85. int        TIMER_ID_START_FLEE=1            local
  86. int        TIMER_ID_ATTACK=2            local
  87.  
  88. # ===========================SUBROUTINES================================================
  89.  
  90. flex    SetDistToIndy            local
  91. flex    ActivateWaypoints        local
  92. flex    DeactivateWaypoints        local
  93. flex    RankWaypointsForFlee     local
  94. flex    RankWaypointsForFleeToEast local
  95. flex     RankWaypointsForFleeToWest    local
  96. flex    ResetWaypointRanks        local
  97.  
  98. end
  99. # ========================================================================================
  100.  
  101. code
  102. startup:
  103.     t_Indy=GetLocalPlayerThing();
  104.     SetThingFlags(t_wolf, 0x80000);
  105.  
  106.    return;
  107.  
  108. # ========================================================================================
  109. entered:
  110.     if (GetSourceRef() == t_Indy)
  111.     {
  112.         for (n_idx = 0; n_idx < NUM_ACTIVATE_WPNT_SECTORS; n_idx = n_idx + 1)
  113.         {
  114.             if (GetSenderRef() == s_ActivateWpnts00[n_idx])
  115.             {
  116.                 call ActivateWaypoints;
  117.             }
  118.         }
  119.         for (n_idx = 0; n_idx < NUM_DEACTIVATE_WPNT_SECTORS; n_idx = n_idx + 1)
  120.         {
  121.             if (GetSenderRef() == s_DeactivateWpnts00[n_idx])
  122.             {
  123.                 call DeactivateWaypoints;
  124.             }
  125.         }
  126.     }
  127.     else if (GetSourceRef() == t_Wolf)
  128.     {
  129.         for (n_idx = 0; n_idx < NUM_AUTO_FLEE_SECTORS; n_idx = n_idx + 1)
  130.         {
  131.             if (GetSenderRef() == s_AutoFlee00[n_idx])
  132.             {
  133. //                DebugPrint("Wolf auto fleeing");
  134.                 AIFlee(t_Wolf, t_Indy);
  135.             }
  136.         }
  137.     }
  138.  
  139.     return;
  140.  
  141. # ========================================================================================
  142. aievent:
  143.     if(!b_active) return;
  144.  
  145.     n_eventType        = GetParam(0);
  146.     n_CrntAIMode    = GetParam(1);
  147.     n_OldAIMode        = GetParam(2);    // only valid for certain n_eventType values
  148.  
  149.     if (n_eventType == 0x100)        // SITHAI_EVENTMODECHANGED
  150.     {
  151.         // if changing to flee mode
  152.         // turn on waypoints
  153.         if ( !BITTEST(n_OldAIMode, 0x800) && BITTEST(n_CrntAIMode, 0x800) )
  154.         {
  155. //            DebugPrint("Entering flee mode");
  156.             AISetSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  157.             f_FleeTime = (MIN_FLEE_TIME + (Rand() * VARIABLE_FLEE_TIME));
  158.             SetTimerEx(f_FleeTime , TIMER_ID_OKAY_TO_STOP_FLEE, 0, 0 );
  159.             b_OKToStopFlee = 0;
  160.             call RankWaypointsForFlee;
  161.         }
  162.         // if exiting flee mode
  163.         // turn off waypoints
  164.         else if ( BITTEST(n_OldAIMode, 0x800) && !BITTEST(n_CrntAIMode, 0x800) )
  165.         {
  166.             call SetDistToIndy;
  167.         
  168.             if (b_AttackOnStopFlee)
  169.             {
  170.                 SetTimerEx(0.01 , TIMER_ID_ATTACK, 0, 0);
  171.                 b_AttackOnStopFlee = 0;
  172.                 AIClearSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  173.                 call ResetWaypointRanks;
  174.             }
  175.             // Consider restarting fleeing if Indy too close
  176.             else if (f_DistToIndy < MIN_FLEE_RESTART_DISTANCE)
  177.             {
  178.                 // Restart using timer to avoid nested mode changes
  179.                 SetTimerEx(0.01 , TIMER_ID_START_FLEE, 0, 0 );
  180.             }
  181.             else
  182.             {
  183.                 AIClearSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  184.                 call ResetWaypointRanks;
  185. //                DebugPrint("Exiting flee mode");
  186.             }
  187.         }
  188.     }
  189.  
  190. return;
  191.  
  192. # ========================================================================================
  193. timer:
  194.     if(!b_active) return;
  195.     t_Indy = GetLocalPlayerThing();
  196.  
  197.     n_TimerID = GetSenderID();
  198.     if (n_TimerID == TIMER_ID_OKAY_TO_STOP_FLEE)
  199.     {
  200.         b_OKToStopFlee = 1;
  201.     }
  202.     else if (n_TimerID == TIMER_ID_START_FLEE)
  203.     {
  204.         call RankWaypointsForFlee;
  205.         AIFlee(t_Wolf, t_Indy);
  206.     }
  207.     else if (n_TimerID == TIMER_ID_ATTACK)
  208.     {
  209.         AISetFireTarget(t_Wolf, t_Indy);
  210.     }
  211.  
  212.  
  213.     return;
  214. # ========================================================================================
  215.  user0:
  216.     if (GetParam(0))
  217.     {
  218.         b_active=1;
  219.         ClearThingFlags(t_wolf, 0x80000);
  220.         call ActivateWaypoints;
  221.     }
  222.     else
  223.     {
  224.         b_active=0;
  225.         SetThingFlags(t_wolf, 0x80000);
  226.     }
  227.     return;
  228.  
  229. # ========================================================================================
  230. arrivedwpnt:
  231.     if(!b_active) return;
  232.     n_Waypoint = GetParam(0);
  233.  
  234.     call SetDistToIndy;
  235.  
  236.     if ( b_OKToStopFlee 
  237.          && (f_DistToIndy > MIN_FLEE_DISTANCE)
  238.          && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  239.          && (RandBetween(0,100) < 90)
  240.          )
  241.     {
  242.         // StopThing before StopFlee so wolf will turn to face indy
  243.         StopThing(t_Wolf);
  244.         AIStopFlee(t_Wolf);
  245.     }
  246.     else if ( b_OKToStopFlee 
  247.          && (f_DistToIndy < MAX_FLEEATTACK_DISTANCE)
  248.          && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  249.          && (RandBetween(0,100) < 30)
  250.          )
  251.     {
  252.         b_AttackOnStopFlee = 1;
  253.         AIStopFlee(t_Wolf);
  254.     }
  255.     else if ( (n_FleeDir == -1)
  256.               && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  257.               )
  258.     {
  259.         // fleeing west
  260.         if (n_Waypoint <=1)
  261.         {
  262.             if (f_DistToIndy > MIN_FLEE_RESTART_DISTANCE)
  263.             {
  264.                 // StopThing before StopFlee so wolf will turn to face indy
  265. //                DebugPrint("Wolf Reached Flee Waypoint and Stopped.");
  266.                 StopThing(t_Wolf);
  267.                 AIStopFlee(t_Wolf);
  268.             }
  269.             else
  270.             {
  271.                 call RankWaypointsForFlee;
  272.             }
  273.         }
  274.     }
  275.     else if ( (n_FleeDir == 1)
  276.               && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  277.               )
  278.     {
  279.         // fleeing east
  280.         if (n_Waypoint >=12)
  281.         {
  282.             if (f_DistToIndy > MIN_FLEE_RESTART_DISTANCE)
  283.             {
  284.                 // StopThing before StopFlee so wolf will turn to face indy
  285. //                DebugPrint("Wolf Reached Flee Waypoint and Stopped.");
  286.                 StopThing(t_Wolf);
  287.                 AIStopFlee(t_Wolf);
  288.             }
  289.             else
  290.             {
  291.                 call RankWaypointsForFlee;
  292.             }
  293.         }
  294.     }
  295.  
  296.     return;
  297.  
  298. # ========================================================================================
  299. SetDistToIndy:
  300.     v_IndyPos = GetThingPos(t_Indy);
  301.     v_WolfPos = GetThingPos(t_Wolf);
  302.  
  303.     f_DistToIndy = VectorDist(v_IndyPos, v_WolfPos);
  304.  
  305.     return;
  306.  
  307. # ========================================================================================
  308. ActivateWaypoints:
  309.     if(!b_active) return;
  310.     if (b_WpntsActive)
  311.     {
  312.         return;
  313.     }
  314.  
  315. //    DebugPrint("ACTIVATING WAYPOINTS FOR WOLF IN COURTYARD AREA");
  316.     b_WpntsActive = 1;
  317.     AISetInstinctWpntMode(t_Wolf);
  318.  
  319.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  320.     {
  321.         AISetWpnt(t_Waypoint00[n_idx], n_idx);
  322.     }
  323.  
  324.     AIConnectWpnts(0, 1);
  325.     AIConnectWpnts(0, 2);
  326.     AIConnectWpnts(0, 3);
  327.     AIConnectWpnts(1, 2);
  328.     AIConnectWpnts(1, 3);
  329.     AIConnectWpnts(2, 3);
  330.     AIConnectWpnts(2, 5);
  331.     AIConnectWpnts(2, 6);
  332.     AIConnectWpnts(3, 4);
  333.     AIConnectWpnts(3, 5);
  334.     AIConnectWpnts(3, 6);
  335.     AIConnectWpnts(3, 7);
  336.     AIConnectWpnts(4, 6);
  337.     AIConnectWpnts(4, 7);
  338.     AIConnectWpnts(5, 6);
  339.     AIConnectWpnts(5, 8);
  340.     AIConnectWpnts(5, 9);
  341.     AIConnectWpnts(6, 7);
  342.     AIConnectWpnts(6, 8);
  343.     AIConnectWpnts(6, 9);
  344.     AIConnectWpnts(6, 10);
  345.     AIConnectWpnts(7, 9);
  346.     AIConnectWpnts(7, 10);
  347.     AIConnectWpnts(8, 9);
  348.     AIConnectWpnts(9, 10);
  349.     AIConnectWpnts(9, 11);
  350.     AIConnectWpnts(10, 11);
  351.     AIConnectWpnts(10, 12);
  352.     AIConnectWpnts(11, 12);
  353.  
  354.     return;
  355.  
  356. # ========================================================================================
  357. DeactivateWaypoints:
  358.     if (!b_WpntsActive)
  359.     {
  360.         return;
  361.     }
  362.  
  363. //    DebugPrint("DEACTIVATING WAYPOINTS FOR WOLF COURTYARD");
  364.     b_WpntsActive = 0;
  365.     AIClearInstinctWpntMode(t_Wolf);
  366.     StopThing(t_Wolf);
  367.  
  368.     return;
  369.  
  370.  
  371. # ========================================================================================
  372. RankWaypointsForFlee:
  373.     if(!b_active) return;
  374.     v_IndyPos = GetThingPos(t_Indy);
  375.     v_Temp = GetThingPos(t_Waypoint06);
  376.  
  377.     if (VectorX(v_IndyPos) > VectorX(v_Temp))
  378.     {
  379.         call RankWaypointsForFleeToWest;
  380.     }
  381.     else
  382.     {
  383.         call RankWaypointsForFleeToEast;
  384.     }
  385.  
  386.     return;
  387.  
  388. # ========================================================================================
  389. RankWaypointsForFleeToWest:
  390.     
  391. //    DebugPrint("Rank waypoints for Flee To West");
  392.     n_FleeDir = -1;
  393.  
  394.     AISetWpntRank(0, 135);
  395.     AISetWpntRank(1, 135);
  396.  
  397.     AISetWpntRank(2, 120);
  398.     AISetWpntRank(3, 120);
  399.  
  400.     AISetWpntRank(4, 105);
  401.     AISetWpntRank(5, 105);
  402.     AISetWpntRank(6, 105);
  403.     AISetWpntRank(7, 105);
  404.  
  405.     AISetWpntRank(8, 90);
  406.     AISetWpntRank(9, 90);
  407.     AISetWpntRank(10, 90);
  408.  
  409.     AISetWpntRank(11, 75);
  410.  
  411.     AISetWpntRank(12, 60);
  412.  
  413.     return;
  414.  
  415. RankWaypointsForFleeToEast:
  416.     
  417. //    DebugPrint("Rank waypoints for Flee To East");
  418.     n_FleeDir = 1;
  419.  
  420.     AISetWpntRank(0, 30);
  421.     AISetWpntRank(1, 30);
  422.     
  423.     AISetWpntRank(2, 45);
  424.  
  425.     AISetWpntRank(3, 60);
  426.     AISetWpntRank(4, 60);
  427.     AISetWpntRank(5, 60);
  428.     AISetWpntRank(8, 60);
  429.  
  430.     AISetWpntRank(6, 75);
  431.     AISetWpntRank(7, 75);
  432.     AISetWpntRank(9, 75);
  433.  
  434.     AISetWpntRank(10, 90);
  435.     AISetWpntRank(11, 90);
  436.     
  437.     AISetWpntRank(12, 105);
  438.  
  439.     return;
  440.  
  441. # ========================================================================================
  442. ResetWaypointRanks:
  443.     if(!b_active) return;
  444. //    DebugPrint("Reset waypoint ranks");
  445.  
  446.     n_FleeDir = 0;
  447.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  448.     {
  449.         AISetWpntRank(n_idx, 0);
  450.     }
  451.  
  452.     return;
  453.  
  454.  
  455.  
  456.  
  457. end
  458.  
  459.